package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsArtificialReplenishmentDetailed;
import com.jy.wms.service.WmsArtificialReplenishmentDetailedService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsArtificialReplenishmentDetailedController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author LH
 * @Date Mon Nov 27 17:20:27 GMT+08:00 2017
 */
@RestController
@RequestMapping("/wmsartificialreplenishmentdetailed")
@Api(value = "/wmsartificialreplenishmentdetailed", description = "关于人工驱动补货明细操作")
public class  WmsArtificialReplenishmentDetailedController extends BaseController<WmsArtificialReplenishmentDetailedService,WmsArtificialReplenishmentDetailed> {

    @PostMapping(value = "add")
    @ApiOperation(value = "新增补货明细",response = JSONObject.class, notes = "新增补货明细")
    public @ResponseBody JSONObject addWmsArtificialReplenishmentDetailed(@RequestBody List<WmsArtificialReplenishmentDetailed> list,HttpSession session) {
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }
        try {
                baseService.baseInsert(list,hzid,ckid);

            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细增加成功", "", JSONArray.fromObject(list).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细增加失败", e.getMessage(), "");
        } catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细增加成功", "", JSONArray.fromObject(list).toString());
        }catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细增加失败", e.getMessage(), "");
        }
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑信息",response = JSONObject.class, notes = "编辑补货单明细")
    public @ResponseBody JSONObject editWmsArtificialReplenishmentDetailed(@RequestBody WmsArtificialReplenishmentDetailed entity) {
        try {
           baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细修改成功", "", JSONObject.fromObject(entity).toString());
        } catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细修改成功", "", JSONObject.fromObject(entity).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细修改失败", e.getMessage(), "");
        }catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细修改失败", e.getMessage(), "");
        }
    }
    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class,  notes = "查询输入</br>{\"ids\":\"明细id集合\",\"id\":\"补货单id\"}")
    public @ResponseBody JSONObject deleteWmsArtificialReplenishmentDetailed(@RequestBody SetAndModifyModel setModel) {
        try {
            Integer flag=baseService.baseDeleteBathPrimaryKeys(setModel.getIds(),setModel.getId());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细删除成功", "", "");
        } catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "补货单明细删除成功", "", "");

        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细删除失败", e.getMessage(), "");
        }catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "补货单明细删除失败", e.getMessage(), "");
        }

    }





    @PostMapping(value = "/list")
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody ResultPage<WmsArtificialReplenishmentDetailed> getWmsArtificialReplenishmentDetailed(@RequestBody WmsArtificialReplenishmentDetailed entity,HttpSession session) {
        Page<WmsArtificialReplenishmentDetailed> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }




    @GetMapping(value = "getWmsArtificialReplenishmentDetailed/{id}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody WmsArtificialReplenishmentDetailed getWmsArtificialReplenishmentDetailedById(@PathVariable("id") String id) {
        WmsArtificialReplenishmentDetailed entity=baseService.baseSelectByPrimaryKey(id);
        return entity;
    }

}
